home *** CD-ROM | disk | FTP | other *** search
- /* fchart - fchart.c */
- /*
- * Gnuplot code
- * Copyright (C) 1986, 1987, 1990 Thomas Williams, Colin Kelley
- *
- * Permission to use, copy, and distribute this software and its
- * documentation for any purpose with or without fee is hereby granted,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation.
- *
- * Permission to modify the software is granted, but not the right to
- * distribute the modified code. Modifications are to be distributed
- * as patches to released version.
- *
- * This software is provided "as is" without express or implied warranty.
- *
- *
- * AUTHORS
- *
- * Original Software:
- * Thomas Williams, Colin Kelley.
- *
- * Gnuplot 2.0 additions:
- * Russell Lang, Dave Kotz, John Campbell.
- *
- * fchart changes and additions:
- * Piotr Filip Sawicki
- *
- * send your comments or suggestions to fs@uwasa.fi
- *
- */
- #include <stdio.h>
- #include <setjmp.h>
- #include <signal.h>
- #include "plot.h"
- #include "fchart.h"
-
- #ifdef MSDOS
- #include <io.h>
- #endif
- #ifdef vms
- #include <unixio.h>
- #endif
- #ifdef __TURBOC__
- #include <graphics.h>
- #endif
-
- /* on some compilers (Turbo C) interrupt is a reserved word
- #ifdef MSDOS
- #define interrupt intrrtn
- #endif
- */
-
- char *getenv(),*strcat(),*strcpy(),*strncpy(),*sprintf();
-
- extern char input_line[];
- extern FILE *outfile;
- extern int term;
- extern struct termentry term_tbl[];
-
- #ifndef STDOUT
- #define STDOUT 1
- #endif
-
- jmp_buf env;
- BOOLEAN interactive;
-
- #ifdef vms
-
- #define HOME "sys$login:"
-
- #else /* vms */
- #ifdef MSDOS
-
- #define HOME "FCHART"
-
- #else /* MSDOS */
-
- #define HOME "HOME"
-
- #endif /* MSDOS */
- #endif /* vms */
-
- #ifdef unix
- #define PLOTRC ".fchart"
- #else
- #define PLOTRC "fchart.ini"
- #endif
-
-
- #ifdef __TURBOC__
- void tc_interrupt()
- #else
- void inter() /* why not void in GNUPLOT? lint cried */
- #endif
- {
- #ifdef MSDOS
- #ifdef __TURBOC__
- (void) signal(SIGINT, tc_interrupt);
- #else
- void ss_interrupt();
- (void) signal(SIGINT, ss_interrupt);
- #endif
- #else
- (void) signal(SIGINT, inter);
- #endif
- (void) signal(SIGFPE, SIG_DFL); /* turn off FPE trapping */
- if (term)
- (*term_tbl[term].text)(); /* hopefully reset text mode */
- (void) fflush(outfile);
- (void) putc('\n',stderr);
- longjmp(env, TRUE); /* return to prompt */
- }
-
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- /* Register the Borland Graphics Interface drivers. If they have been */
- /* included by the linker. */
- #ifdef __TURBOC__
- registerbgidriver(CGA_driver);
- registerbgidriver(EGAVGA_driver);
- registerbgidriver(Herc_driver);
- #endif
-
- setbuf(stderr,(char *)NULL);
- outfile = stdout;
-
- interactive = FALSE;
- init_terminal(); /* Can set term if it wishes. */
-
- #ifdef TERM /* set term according to predefined type */
- term = change_term(TERM, strlen(TERM));
- if (term < 0)
- term = 0; /* ignore error */
- #endif
-
- interactive = isatty(fileno(stdin));
- if (interactive) {
- show_version();
- if (term != 0)
- fprintf(stderr,"\tTerminal type: '%s'\n\n",term_tbl[term].name);
- }
-
- if (!setjmp(env)) {
- /* first time */
- interrupt_setup();
- load_rcfile();
- if (argc > 1 && change_term(argv[1],strlen(argv[1])) < 1) {
- interactive = 0;
- int_error("wrong terminal type as option, aborted",NO_CARET);
- }
- } else {
- /* come back here from int_error() */
- #ifdef vms
- /* after catching interrupt */
- /* VAX stuffs up stdout on SIGINT while writing to stdout,
- so reopen stdout. */
- if (outfile = stdout) {
- if ( (stdout = freopen("SYS$OUTPUT","w",stdout)) == NULL) {
- /* couldn't reopen it so try opening it instead */
- if ( (stdout = fopen("SYS$OUTPUT","w")) == NULL) {
- /* don't use int_error here - causes infinite loop! */
- fprintf(stderr,"Error opening SYS$OUTPUT as stdout\n");
- }
- }
- outfile = stdout;
- }
- #endif /* VMS */
- if (!interactive)
- done(IO_ERROR); /* exit on non-interactive error */
- }
-
-
- while(TRUE)
- com_line();
-
- /* done(IO_SUCCESS); */
- }
-
-
- /* Set up to catch interrupts */
- interrupt_setup()
- {
- #ifdef MSDOS
- #ifdef __TURBOC__
- (void) signal(SIGINT, tc_interrupt); /* go there on interrupt char */
- #else
- void ss_interrupt();
- save_stack(); /* work-around for MSC 4.0/MSDOS 3.x bug */
- (void) signal(SIGINT, ss_interrupt);
- #endif
- #else /* MSDOS */
- (void) signal(SIGINT, inter); /* go there on interrupt char */
- #endif /* MSDOS */
- }
-
- /* Look for a fchart start-up file */
- load_rcfile()
- {
- register FILE *plotrc;
- static char home[80];
- static char rcfile[sizeof(PLOTRC)+80];
-
- /* Look for a fchart init file in . or home directory */
- #ifdef vms
- (void) strcpy(home,HOME);
- #else
- (void) strcat(strcpy(home,getenv(HOME)),"/");
- #endif /* vms */
- (void) strcpy(rcfile, PLOTRC);
- plotrc = fopen(rcfile,"r");
- if (plotrc == (FILE *)NULL) {
- (void) sprintf(rcfile, "%s%s", home, PLOTRC);
- plotrc = fopen(rcfile,"r");
- }
- if (plotrc)
- load_file(plotrc);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-